package com.woniuxy.platform.core.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.common.CommonResult;
import com.woniuxy.platform.core.service.PlOrderitemService;
import com.woniuxy.platform.core.vo.OrderItemVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-07-12
 */
@RestController
@RequestMapping("plOrderitem")
public class PlOrderitemController {

    @Resource
    private PlOrderitemService orderitemService;

    /**
     * Description : 所有门店未付款订单
     * ChangeLog : 1. 创建 (2021/7/12 11:04 [fulang]);
     *
     * @param startpage
     * @param pagesize
     * @return com.woniuxy.common.CommonResult<com.github.pagehelper.PageInfo < com.woniuxy.platform.core.vo.OrderItemVo>>
     */
    @GetMapping("selectUnpaid/{startpage}/{pagesize}")
    public CommonResult<PageInfo<OrderItemVo>> selectUnpaid(@PathVariable int startpage, @PathVariable int pagesize) {
        PageHelper.startPage(startpage, pagesize);
        List<OrderItemVo> plOrderitems = orderitemService.selectUnpaid();
        List<OrderItemVo> chinese = chinese(plOrderitems);
        Page<OrderItemVo> page = (Page<OrderItemVo>) chinese;
        PageInfo<OrderItemVo> info = new PageInfo<>(page);
        return CommonResult.success(info);
    }

    /**
     * Description : 所有门店未收货订单
     * ChangeLog : 1. 创建 (2021/7/12 11:05 [fulang]);
     *
     * @param startpage
     * @param pagesize
     * @return com.woniuxy.common.CommonResult<com.github.pagehelper.PageInfo < com.woniuxy.platform.core.vo.OrderItemVo>>
     */
    @GetMapping("selectUnChecked/{startpage}/{pagesize}")
    public CommonResult<PageInfo<OrderItemVo>> selectUnChecked(@PathVariable int startpage, @PathVariable int pagesize) {
        PageHelper.startPage(startpage, pagesize);
        List<OrderItemVo> plOrderitems = orderitemService.selectUnChecked();
        List<OrderItemVo> chinese = chinese(plOrderitems);
        Page<OrderItemVo> page = (Page<OrderItemVo>) chinese;
        PageInfo<OrderItemVo> info = new PageInfo<>(page);
        return CommonResult.success(info);
    }

    /**
     * Description :所有门店未服务订单
     * ChangeLog : 1. 创建 (2021/7/12 11:05 [fulang]);
     *
     * @param startpage
     * @param pagesize
     * @return com.woniuxy.common.CommonResult<com.github.pagehelper.PageInfo < com.woniuxy.platform.core.vo.OrderItemVo>>
     */
    @GetMapping("selectUnServiced/{startpage}/{pagesize}")
    public CommonResult<PageInfo<OrderItemVo>> selectUnServiced(@PathVariable int startpage, @PathVariable int pagesize) {
        PageHelper.startPage(startpage, pagesize);
        List<OrderItemVo> plOrderitems = orderitemService.selectUnServiced();
        List<OrderItemVo> chinese = chinese(plOrderitems);
        Page<OrderItemVo> page = (Page<OrderItemVo>) chinese;
        PageInfo<OrderItemVo> info = new PageInfo<>(page);
        return CommonResult.success(info);
    }

    /**
     * Description : 所有门店待评价订单
     * ChangeLog : 1. 创建 (2021/7/12 11:06 [fulang]);
     *
     * @param startpage
     * @param pagesize
     * @return com.woniuxy.common.CommonResult<com.github.pagehelper.PageInfo < com.woniuxy.platform.core.vo.OrderItemVo>>
     */
    @GetMapping("selectUnEvaluate/{startpage}/{pagesize}")
    public CommonResult<PageInfo<OrderItemVo>> selectUnEvaluate(@PathVariable int startpage, @PathVariable int pagesize) {
        PageHelper.startPage(startpage, pagesize);
        List<OrderItemVo> plOrderitems = orderitemService.selectUnEvaluate();
        List<OrderItemVo> chinese = chinese(plOrderitems);
        Page<OrderItemVo> page = (Page<OrderItemVo>) chinese;
        PageInfo<OrderItemVo> info = new PageInfo<>(page);
        return CommonResult.success(info);
    }

    /**
     * Description : 所有门店待售后服务的订单
     * ChangeLog : 1. 创建 (2021/7/12 11:07 [fulang]);
     *
     * @param startpage
     * @param pagesize
     * @return com.woniuxy.common.CommonResult<com.github.pagehelper.PageInfo < com.woniuxy.platform.core.vo.OrderItemVo>>
     */
    @GetMapping("selectUnAfterSale/{startpage}/{pagesize}")
    public CommonResult<PageInfo<OrderItemVo>> selectUnAfterSale(@PathVariable int startpage, @PathVariable int pagesize) {
        PageHelper.startPage(startpage, pagesize);
        List<OrderItemVo> plOrderitems = orderitemService.selectUnAfterSale();
        List<OrderItemVo> chinese = chinese(plOrderitems);
        Page<OrderItemVo> page = (Page<OrderItemVo>) chinese;
        PageInfo<OrderItemVo> info = new PageInfo<>(page);
        return CommonResult.success(info);
    }

    /**
     * Description : 所有门店已完成订单
     * ChangeLog : 1. 创建 (2021/7/12 11:07 [fulang]);
     *
     * @param startpage
     * @param pagesize
     * @return com.woniuxy.common.CommonResult<com.github.pagehelper.PageInfo < com.woniuxy.platform.core.vo.OrderItemVo>>
     */
    @GetMapping("selectFinished/{startpage}/{pagesize}")
    public CommonResult<PageInfo<OrderItemVo>> selectFinished(@PathVariable int startpage, @PathVariable int pagesize) {
        PageHelper.startPage(startpage, pagesize);
        List<OrderItemVo> plOrderitems = orderitemService.selectFinished();
        List<OrderItemVo> chinese = chinese(plOrderitems);
        Page<OrderItemVo> page = (Page<OrderItemVo>) chinese;
        PageInfo<OrderItemVo> info = new PageInfo<>(page);
        return CommonResult.success(info);
    }

    /**
     * Description : 生成订单类型,状态中文
     * ChangeLog : 1. 创建 (2021/7/12 11:36 [fulang]);
     *
     * @param orderItemVos
     * @return java.util.List<com.woniuxy.store.core.vo.OrderItemVo>
     */
    public List<OrderItemVo> chinese(List<OrderItemVo> orderItemVos) {
        for (OrderItemVo orderItem : orderItemVos
        ) {
            if (orderItem.getStatus() == 0) {
                orderItem.setStatusch("待付款");
            }
            if (orderItem.getStatus() == 1) {
                orderItem.setStatusch("待收货");
            }
            if (orderItem.getStatus() == 2) {
                orderItem.setStatusch("待服务");
            }
            if (orderItem.getStatus() == 3) {
                orderItem.setStatusch("待评价");
            }
            if (orderItem.getStatus() == 4) {
                orderItem.setStatusch("待售后");
            }
            if (orderItem.getStatus() == 5) {
                orderItem.setStatusch("已完成");
            }
            if (orderItem.getOrdertype() == 0) {
                orderItem.setOrdertypech("商品");
            } else {
                orderItem.setOrdertypech("服务");
            }
        }
        return orderItemVos;
    }
    /**
     * Description : 查看所有订单
     * ChangeLog : 1. 创建 (2021/7/13 15:22 [fulang]);
     * @param startpage
     * @param pagesize
     * @return com.woniuxy.common.CommonResult<com.github.pagehelper.PageInfo<com.woniuxy.platform.core.vo.OrderItemVo>>
    */
    @GetMapping("selectAll/{startpage}/{pagesize}")
    public CommonResult<PageInfo<OrderItemVo>> selectAll(@PathVariable int startpage, @PathVariable int pagesize) {
        PageHelper.startPage(startpage, pagesize);
        List<OrderItemVo> plOrderitems = orderitemService.selectAll();
        List<OrderItemVo> chinese = chinese(plOrderitems);
        Page<OrderItemVo> page = (Page<OrderItemVo>) chinese;
        PageInfo<OrderItemVo> info = new PageInfo<>(page);
        return CommonResult.success(info);
    }
}

